package com.kuang.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();

        if (request.getRequestURI().contains("zhuce")) {
            System.out.println("拦截啊啊啊啊zhuce");
            return true;
        }
        //登陆页面也会放行
        if (request.getRequestURI().contains("login")) {
            System.out.println("拦截啊啊啊啊login");
            return true;
        }
        if (request.getRequestURI().contains("shouye")) {
            System.out.println("拦截啊啊啊啊shouye");
            return true;
        }

        //放行:判断什么情况下登陆
        if (session.getAttribute("USERID") != null) {
            System.out.println("拦截啊啊啊啊userid");
            return true;
        }

        //判断什么情况下是没有登陆的
        request.getRequestDispatcher("/web/index.jsp").forward(request,response);
        return false;
    }
}